<template>
	<view class="contont">
		<nav-bar :title="title" :iconLeft="true" />
		<view class="content-bgc">
			<view class="b-con">
				<view style="margin-top: 20rpx;">
					<up-cell-group :border="false">
						<up-cell title="委外发料单号">
							<template #value>
								<view class="cell-text">{{ detail_record.code }} </view>
							</template>
						</up-cell>
						<up-cell title="委外加工单号">
							<template #value>
								<view class="cell-text">{{ detail_record.machining_code }} </view>
							</template>
						</up-cell>
						<up-cell title="发料日期">
							<template #value>
								<view class="cell-text">{{ detail_record.issue_date }}</view>
							</template>
						</up-cell>
						<up-cell title="备注">
							<template #value>
								<view class="cell-text" style="width: 70%;">{{ detail_record.desc }}</view>
							</template>
						</up-cell>
					</up-cell-group>
				</view>
			</view>
			<view class="b-con">
				<up-cell-group :border="false">
					<up-cell :isLink="true" :border="false" :title="`产品：总数量（${car_list.length}）`" @click="car_popupShow = true">
						<template #value>
							<view class="cell-text">点击查看 </view>
						</template>
					</up-cell>
				</up-cell-group>
			</view>
			<custom-popup :popupShow="car_popupShow" mode="bottom" :title="'生产'" @close="car_popupShow = false" height="70vh">
				<z-paging v-if="car_popupShow" ref="paging_car" :refresher-enabled="false" :loading-more-enabled="false" :fixed="false" v-model="car_list"
					@query="queryList_car">
					<uni-card v-for="(item, index) in car_list" :key="index" :title="item.name" :sub-title="item.code"
						margin="5px" spacing="0">
						<view class="ctent">规格：{{ item.specification }}</view>
						<view class="con">
							<view class="ctent">基本单位：{{ item.unit_main }}</view>
							<view class="ctent">加工单价(元)：{{ item.machining_price }}</view>
						</view>
						<view style="background-color: #f2f5f9;">
							<uni-card v-for="val in item.children" :title="val.name" :sub-title="val.code" margin="5px" spacing="0">
								<view class="ctent">规格：{{ val.specification }}</view>
								<view class="con">
									<view class="ctent ">基本单位：{{ val.unit_main }}</view>
									<view class="ctent ">BOM量：{{ val.bom_num }}</view>
								</view>
								<view class="con">
									<view class="ctent ">需要发料数量：{{ val.num }}</view>
									<view class="ctent">已发料数量：{{ val.up_num }}</view>
								</view>
								<view class="ctent">发料仓库：{{ val.wareInfo }}</view>
								<view class="con">
									<view class="ctent">本期发料数量：{{ val.now_num }}</view>
								</view>
							</uni-card>
						</view>
					</uni-card>
				</z-paging>
			</custom-popup>
		</view>
	</view>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import enMaterialApi from '../../../api/entrust/en_material'

const detail_record = ref({})
const title = '委外发料出库详情';
onLoad(option => {
	get_detail(option.id);
})

const car_popupShow = ref(false)
const car_list = ref([])
function get_detail(id) {
	enMaterialApi.machining_issue_detail(id).then(data => {
		detail_record.value = data
		car_list.value = data.table_data.map(v => {
			v.children = v.children.map(k => {
				const obj = k.warehouse_list.find(j => j.id == k.warehouse)
				k.wareInfo = obj.info
				return k
			})
			return v
		})
	})
}
const paging_car = ref(null)
function queryList_car() {
	paging_car.value.complete(car_list.value);
}

</script>

<style lang="scss"></style>